<?php

namespace App\Listeners;

use Codingyu\LaravelUEditor\Events\Uploading;

class UploadingNotification
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param object $event
     * @return void
     */
    public function handle(Uploading $event)
    {
        $old_name = $event->file->getClientOriginalName(); //旧文件名
        $new_name = md5(uniqid()) . '.' . $event->file->getClientOriginalExtension(); //新文件名
        return $event->filename = str_replace($old_name, $new_name, $event->filename); //替换文件名
    }
}

